#include<fstream>
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<map>
#include<vector>
#include<cstdlib>


#include "Charnode.h"
#include "HuffmanCode.h"
#include "globals.h"
#include "bitops.h"
#include "CompressionWriting.h"

using namespace std;

int main(int argc, char * argv[])
{
	LOG(__func__);
	if(argc != 3)
	{
		cout<<"Usage "<<argv[0]<< " Input_file "<<"Output_file\n";
		exit(0);
	}
	
	Huffman<char> huff(argv[1]);
	//huff.displayCharactermap();

	cout << endl << endl;
	//huff.displayHuffmanTable();

	map<char, string> huffmanTable = huff.getHuffmanTable();

	CompressionWriting<char> writingObj(huff.getRoot(), huffmanTable, huff.getFrequencyMap(), argv[2], argv[1]);
	writingObj.writeCompressedDataToFile();
	cout<<"Done!"<<endl;
	//writingObj.displayOutputFile();

	//test();

	//cin.get();
}